﻿@inherits LoginPage

<div class="login">
    <div class="login-head">
        <div class="login-logo">
            <a href="@Config.SiteUrl" target="_blank"><img src="@Index.LogoUrl" /></a>
            <div>@Language["App.SubTitle"]</div>
        </div>
        <ul class="kui-menu">
            <li><a href="@Config.SiteUrl/doc" target="_blank">@Language["Document"]</a></li>
            @if (Config.App.IsLanguage)
            {
                <li style="text-align:center;"><AntLanguage OnChanged="StateChanged" /></li>
            }
            <li style="margin-left:15px;"><AntTheme Theme="@Index.Theme" OnChanged="Index.SetTheme" /></li>
        </ul>
    </div>
    <div class="login-body">
        <div class="login-left">
            <ul>
                <li>@Language["OpenSource"]</li>
                <li>@Language["LowCode"]</li>
                <li>@Language["ModernUI"]</li>
            </ul>
            <img src="_content/Known.Shared/img/login.png" />
        </div>
        <div class="login-form">
            <div class="login-form-body">
                <Tooltip Title="@Language["Tip.SwitchUIType"]" Style="position:absolute;top:0;right:0;">
                    <Segmented TValue="string" Value="Index.UIType.ToString()" Labels="uiTypes" OnChange="OnUIChanged" />
                </Tooltip>
                @if (Index.UIType == UIType.AntDesign)
                {
                    <Known.AntBlazor.LoginForm Model="Model" OnLogin="OnUserLogin" OnSendSMS="OnSendSMS" />
                }
                else if (Index.UIType == UIType.Bootstrap)
                {
                    <Known.BootBlazor.LoginForm Model="Model" OnLogin="OnUserLogin" />
                }
            </div>
        </div>
    </div>
    <div class="login-copyright"><PageFooter /></div>
</div>

@code {
    private string[] uiTypes = [
        UIType.AntDesign.ToString(),
        UIType.Bootstrap.ToString()
    ];

    [CascadingParameter] private Index Index { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        Model.UserName = "Admin";
        Model.Password = "888888";
    }

    private void OnUIChanged(string item)
    {
        var type = Utils.ConvertTo<UIType>(item);
        Index.SetUIType(type);
    }

    private Task<Known.Result> OnSendSMS(string phone)
    {
        return Known.Result.SuccessAsync($"Send to {phone}");
    }
}